package org.yi.utils;

public class RandomUtils {
	
	private static final Integer DIGIT_START = 48;
	private static final Integer DIGIT_END = 57;
	
	private static final Integer UPPER_CHAR_START = 65;
	private static final Integer UPPER_CHAR_END = 90;

	/**
	 * generate a random name
	 * @return
	 */
	public static String randomName() {
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<6;i++) {
			sb.append((char) MathUtils.randomInt(UPPER_CHAR_START, UPPER_CHAR_END));
		}
		for(int i=0;i<6;i++) {
			sb.append((char) MathUtils.randomInt(DIGIT_START, DIGIT_END));
		}
		return sb.toString();
	}
	
	/**
	 * generate a random password
	 * @return
	 */
	public static String randomPassword() {
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<10;i++) {
			if(i % 2 == 0) {
				sb.append((char) MathUtils.randomInt(UPPER_CHAR_START, UPPER_CHAR_END));
			} else {
				sb.append( (char) MathUtils.randomInt(DIGIT_START, DIGIT_END));
			}
		}
		return sb.toString();
	}
	
	/**
	 * generate a random string
	 * @param length
	 * @return
	 */
	public static String randomStr(int length) {
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<length;i++) {
			sb.append((char) MathUtils.randomInt(UPPER_CHAR_START, UPPER_CHAR_END));
		}
		return sb.toString();
	}
	
	/**
	 * 产生指定长度的
	 * @param length
	 * @return
	 */
	public static Long randomLong(int length) {
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<length;i++) {
			sb.append(MathUtils.randomInt(0, 9));
		}
		return Long.parseLong(sb.toString());
	}

	
}
